package cn.tedu.peipei.comment.service.impl;

import cn.tedu.peipei.comment.mapper.CommentMapper;
import cn.tedu.peipei.comment.pojo.dto.CommentDto;
import cn.tedu.peipei.comment.pojo.entity.Comment;
import cn.tedu.peipei.comment.pojo.vo.CommentVO;
import cn.tedu.peipei.comment.service.CommentService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    CommentMapper mapper;

    @Override
    public void addNew(CommentDto commentDTO) {
        Comment comment = new Comment();
        BeanUtils.copyProperties(commentDTO,comment);
        comment.setCreateTime(new Date());
        mapper.insert(comment);
        //每新增一条评论数据,评论量+1
        mapper.updateCommentCountById(comment.getContentId());
    }

    @Override
    public List<CommentVO> listByContentId(Long id) {
        return mapper.selectByContentId(id);
    }

}
